package zuoye;

import java.util.Arrays;
import java.util.Random;

public class Bubble4 {
	/*
	 * java定义一个3*5的二维数组，用来存储某班级3位学员的5门课的成绩 定义一个3*5的二维数组，用来存储某班级3位学员的5门课的成绩；这5门课
	 *  按存储顺序依次为：Java，JSP，CoreJava，MySQL和HTML5。
	 * （1）循环给二维数组的每一个元素赋0~100之间的随机整数。 (int) (Math.random() * 100)
	 * （2）按照列表的方式输出这些学员的每门课程的成绩。 （3）要求编写程序求每个学员的总分，将其保留在另外一个一维数组中。
	 * （4）要求编写程序求所有学员的某门课程的平均分
	 */
	public static void main(String[] args) {
		Random random = new Random();
		int[][] scores = new int[3][5];
		for(int i=0;i < scores.length;i++) {
			for(int j=0;j < scores[i].length;j++) {
				scores[i][j] = random.nextInt(101); 
			}
		}
		System.out.println(Arrays.deepToString(scores)); 
		System.out.println("学号\t\tC++\t\tJSP\t\tJava\t\tMySQL\t\tHTML5\t\t\t总成绩");
		int[] sums = new int[3];
		int[] avgs = new int[5];
		int total = 0;
		for (int i = 0; i < scores.length; i++) {
			System.out.print((i+1)+"\t\t");
			for (int j = 0; j < scores[i].length; j++) {
				System.out.print(scores[i][j] + "\t\t");
				sums[i] += scores[i][j];
				avgs[j]+= scores[i][j];
			}
			total += sums[i];
			System.out.println("\t" + sums[i]);
		}
		System.out.print("平均分\t\t");
		for (int i = 0; i < avgs.length; i++) {
			System.out.print(avgs[i]/3+"\t\t");
		}
		/*int sum = 0;
		int sum1 = 0;
		int sum2 = 0;
		int sum3 = 0;
		int sum4 = 0;
		int sum5 = 0;
		int avg1 = 0;
		int avg2 = 0;
		int avg3 = 0;
		int avg4 = 0;
		int avg5 = 0;

		for (int i = 0; i < scores.length; i++) {
			sum = 0;
			System.out.println("输入第" + (i + 1) + "名同学的成绩");
			for (int j = 0; j < scores[i].length; j++) {
				switch (j) {
				case 0:
					System.out.print("Java:");
					break;
				case 1:
					System.out.print("Jsp:");
					break;
				case 2:
					System.out.print("CoreJava:");
					break;
				case 3:
					System.out.print("MySQL:");
					break;
				default:
					System.out.print("HTML5:");
					break;
				}

				scores[i][j] = input.nextInt();
				sum += scores[i][j];

			}
			System.out.println("总分：" + sum);
			System.out.println("******************************");

		}
		for (int i = 0; i < scores.length; i++) {
			for (int j = 0; j < 5; j++) {
				if (j == 0) {
					sum1 += scores[i][j];
				}
				if (j == 1) {
					sum2 += scores[i][j];
				}
				if (j == 2) {
					sum3 += scores[i][j];
				}
				if (j == 3) {
					sum4 += scores[i][j];
				}
				if (j == 4) {
					sum5 += scores[i][j];
				}
			}
		}
		avg1 = sum1 / 3;
		avg2 = sum2 / 3;
		avg3 = sum3 / 3;
		avg4 = sum4 / 3;
		avg5 = sum5 / 3;
		System.out.println("java的平均分为：" + avg1);
		System.out.println("JSP的平均分为：" + avg2);
		System.out.println("CoreJava的平均分为：" + avg3);
		System.out.println("MySQL：" + avg4);
		System.out.println("HTML5：" + avg5);*/

	}
}
